package sample.note;

import android.Manifest;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import br.com.dina.ui.widget.UITableView;
import lombok.SneakyThrows;

public class EventListFragment extends Fragment {
    UITableView tableView;

    @SneakyThrows
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_event_list, container, false);
        tableView = view.findViewById(R.id.tableView);

        loadList();
        return view;
    }
    void loadList(){
        final String[] list = new String[]{Manifest.permission.WRITE_CALENDAR, Manifest.permission.READ_CALENDAR};
        boolean permitted = AppWrapper.reqPermit(list, getActivity());
        if(!permitted){
            return;
        }
        AppWrapper.insertEventContent();
                Log.e("xxx", "inserted");

        String[] columns = new String[]{"title", "description", "eventLocation", "dtstart"};
        AppWrapper.queryEventContent(cur -> {
            for(String i: columns){
                String val = cur.getString(cur.getColumnIndex(i));
                Log.e("xxx", i + ":" + val);
                tableView.addBasicItem(i, val);
            }
        });
        tableView.commit();
    }
}
